#include <stdio.h>
#include <string.h>

//自我实现memmove
//原理：在同一数组中转移，如果目标在源之前，则从头开始转，剩下的从后开始转
void* My_memmove(void* dst, void* src, size_t num)
{
    //如果dst头在src头之前
    if (dst < src)
    {
        //前->后
        while (num--)
        {
            *(char*)dst++ = *(char*)src++;
        }
    }
    else 
    {
        //后->前
        while (num--)
        {
            *((char*)dst + num) = *((char*)src + num);
        }
    }
}
   
    

int main()
{
    int arr1[] = {1, 2, 3, 4, 5, 6, 7, 8, 9, 0};
    //memmove(arr1, arr1 + 4, 5 * sizeof(arr1[0]));
    My_memmove(arr1 + 4, arr1, 5 * sizeof(arr1[0]));
    for (int i = 0; i < 10 ; i++)
    {
        printf("%d ", arr1[i]);
    }
    return 0;
}